<template>
  <div class="wrap" :key="1">
    <div class="left">
      <svg class="icon" aria-hidden="true">
        <use xlink:href="#icon-icon_xiangji"></use>
      </svg>
      <div class="left_name">
        <p>一个摄影网站</p>
        <p :class="titles">Born for Interest</p>
      </div>
    </div>
    <div class="search search_head">
      <button>
        <svg class="button_icon" aria-hidden="true">
          <use xlink:href="#icon-sousuo2"></use>
        </svg>
      </button>
      <input type="text" v-model="searchValue" placeholder="search for something you need">
    </div>
    <div class="right" v-if="!userName">
      <div class="admin_login" @click="HandlerAdminLog()">我是管理员</div>
      <div class="right_login" @click="HandlerLog()">
        <span>登录</span>
        <i class="iconfont icon-denglu1"></i>
      </div>
      <div class="right_reg" @click="HandlerReg()">
        注册
        <i class="iconfont icon-zhuce1"></i>
      </div>
    </div>
    <div class="right" v-else>
      <div class="right_login">
        <i class="iconfont icon-notice"></i>
      </div>
      <div class="right_reg">
        <Dropdown trigger="custom" :visible="visible" style="margin-left: 20px">
          <p @click="handleOpen">
            <i class="iconfont icon-iconzhucetouxiang"></i>
          </p>
          <DropdownMenu slot="list">
            <div style="text-align: center;margin:10px;">
              <Button type="primary" @click="handleInto">{{this.userName}}个人中心</Button>
            </div>
            <div style="text-align: center;margin:10px;">
              <Button type="primary" @click="handleClose">退出</Button>
            </div>
          </DropdownMenu>
        </Dropdown>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "HeadIndex",
  props: {
    title: String
  },
  data() {
    return {
      visible: false,
      userName: sessionStorage.userName,
      titles: this.title,
      searchValue: ""
    };
  },
  methods: {
    handleInto() {
      this.$router.push("/PrivateIndex");
    },
    handleOpen() {
      this.visible = true;
    },
    handleClose() {
      this.visible = false;
      sessionStorage.clear();
      this.$router.push("/Login");
    },
    HandlerAdminLog() {
      this.$router.push("/AdminLogin");
    },
    HandlerReg() {
      this.$router.push("/Register");
    },
    HandlerLog() {
      this.$router.push("/Login");
    }
  },
  watch: {
    title: function(newValue, oldValue) {
      this.titles = newValue;
    }
  }
};
</script>

<style scoped>
.left_name {
  color: #fff;
}
.ivu-btn-primary.active,
.ivu-btn-primary:active,
.ivu-btn-primary:hover {
  color: #fff !important;
}
.ivu-btn-primary {
  color: #fff;
  background-color: #000;
  border-color: #000;
}
.ivu-dropdown-menu {
  min-width: auto;
}
</style>
